<?php

namespace App\Admin\Controller;

use SinglePHP\BaseController;
use SinglePHP\Cookie;
use SinglePHP\Log;
use function SinglePHP\is_post;

class Account extends BaseController
{
    public function __construct()
    {
        Log::notice('123');
        parent::__construct();
        $identity = Cookie::get('identity');
        if (isset($identity['username'])) {
            $this->redirect('/admin.php/admin');
        }
    }

    public function login()
    {
        if (is_post()) {
            if ($_POST['username'] == 'admin' && $_POST['password'] == 'admin') {
                Cookie::set('identity', $_POST);
                dump($identity = Cookie::get('identity'));die;
                $this->redirect('/admin.php/admin');
            } else {
                dump('用户名或密码错误！');
            }
            dump($identity = Cookie::get('identity'));die;
            die;
        }
        $this->display();
    }

    public function register()
    {

    }

    public function oauth()
    {

    }
}